//
//  OtherChatCell.m
//  diaoyuren
//
//  Created by 钓鱼人 on 16/4/22.
//  Copyright © 2016年 game. All rights reserved.
//
#import "LoginController.h"
#import "OtherChatCell.h"
#import "YYText.h"
#import "YYLabel.h"
#import "NSString+HtmlCharact.h"
#import "NSString+DealTheMessage.h"
#import "UIImageView+WebCache.h"
@interface OtherChatCell ()

@property (weak, nonatomic) IBOutlet MBLabelWithFontAdapter *timeLab;
@property (weak, nonatomic) IBOutlet UIImageView *headImage;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headWidth;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headHight;

@property (weak, nonatomic) IBOutlet UIImageView *chatImage;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *chatWidth;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *chatHight;

@property (weak, nonatomic) IBOutlet YYLabel *chatComtent;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *contentwidth;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *contentHight;
@end

@implementation OtherChatCell

- (void)awakeFromNib {
    self.selectionStyle = 0;
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.chatComtent.backgroundColor = [UIColor clearColor];
    
    UIImage *image = [UIImage imageNamed:@"gray_dialog"];
    
    self.chatImage.image = [image stretchableImageWithLeftCapWidth:image.size.width/2 topCapHeight:image.size.height/2];
    
    self.headHight.constant = SCREEN_HEIGHT*0.05;
    self.headWidth.constant = self.headHight.constant;
    radius(self.headImage, self.headHight.constant/2);
    
    self.chatComtent.textVerticalAlignment = YYTextVerticalAlignmentCenter;
    self.chatComtent.numberOfLines = 0;
    self.chatComtent.font = font(SCREEN_WIDTH*0.053);
    
}

-(void)setModel:(MyPmListModel *)model{
    _model = model;
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:_model.avatar]];
    self.timeLab.text = _model.vdateline;

    
    
    
    NSMutableAttributedString* mas = [[_model.message filterresult] dealTheMessage];
    self.chatComtent.attributedText = mas;
    
    CGFloat www = SCREEN_WIDTH-(self.headHight.constant+20)*2;
    
    CGSize size = CGSizeMake(www, CGFLOAT_MAX);
    YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:size text:mas];
    
    
    self.contentwidth.constant = layout.textBoundingSize.width;
    self.chatWidth.constant = layout.textBoundingSize.width+20;
    
    self.contentHight.constant = layout.textBoundingSize.height;
    self.chatHight.constant = layout.textBoundingSize.height+20;
    
    self.height =  layout.textBoundingSize.height+SCREEN_HEIGHT*0.1;

    
    
}

@end
